﻿Imports System.Data.SqlClient
Imports PhDir.DAL
Imports PhDir.Model
Imports PhDir.Repository

Namespace Repository.Department

    Public Class SelectAllDepartments
        Implements ISelectAll(Of Model.Department)

        Overridable Function SelectAll() As List(Of Model.Department) Implements ISelectAll(Of Model.Department).SelectAll
            Dim sqlDataReader As SqlDataReader             = Nothing
            Dim departments   As List(Of Model.Department) = New List(Of Model.Department)

            Using dbConnection = New DbConnection(DbContext.PhoneContext)

                dbConnection.CommandText = StoredProceduresName.GetAllDepartments
                sqlDataReader            = dbConnection.ExecuteReader()

                While sqlDataReader.Read()
                    departments.Add(New Model.Department With {.DepartmentId   = sqlDataReader("DepartmentId"),
                                                               .DepartmentName = sqlDataReader("Name")})
                End While

            End Using

            Return departments
        End Function

    End Class

End Namespace
